package com.rpay.admin.controller.feedback;

import com.rpay.admin.param.feedback.UpdateFeedback;
import com.rpay.common.dto.feedback.FeedbackDTO;
import com.rpay.common.dto.feedback.FeedbackQuertDTO;
import com.rpay.common.vo.PcsResult;
import com.rpay.service.feedback.IFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "api/feedback")
@Validated
public class FeedbackController {
    @Autowired
    private IFeedbackService iFeedbackService;

    @GetMapping(value = "")
    public PcsResult list(
            @RequestParam(name = "page", defaultValue = "1") Integer page,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "startTime", defaultValue = "") String startTime,
            @RequestParam(name = "endTime", defaultValue = "") String endTime
    ) {
        FeedbackQuertDTO query = new FeedbackQuertDTO();
        query.setStartTime(startTime);
        query.setEndTime(endTime);
        query.setPage((page - 1) * pageSize);
        query.setPageSize(pageSize);
        FeedbackQuertDTO data = iFeedbackService.list(query, page, pageSize, startTime, endTime);
        return PcsResult.build(data);
    }

    @PatchMapping(value = "/detail/{id}")
    public PcsResult update(@Validated @RequestBody UpdateFeedback updateFeedback, @PathVariable("id") Integer id) {
        FeedbackDTO feedbackDTO = new FeedbackDTO();
        feedbackDTO.setId(id);
        feedbackDTO.setIsRead(updateFeedback.getIsRead());
        iFeedbackService.patch(feedbackDTO);
        return new PcsResult();
    }

    @DeleteMapping(value = "/detail/{id}")
    public PcsResult delete(@PathVariable Integer id) {
        iFeedbackService.delete(id);
        return new PcsResult();
    }
}
